using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;


namespace OpenProject.DataObjects{
    /// <summary>
    /// Strongly-typed collection for the ItemCategory class.
    /// </summary>
    [Serializable]
    public partial class ItemCategoryCollection : ActiveList<ItemCategory, ItemCategoryCollection> 
    {       
        public ItemCategoryCollection() {}

    }

    /// <summary>
    /// This is an ActiveRecord class which wraps the ItemCategory table.
    /// </summary>
    [Serializable]
    public partial class ItemCategory : ActiveRecord<ItemCategory>
    {
    
	    #region Default Settings
	    protected static void SetSQLProps() 
	    {
		    GetTableSchema();
	    }

	    #endregion
        #region Schema Accessor
	    public static TableSchema.Table Schema
        {
            get
            {
                if (BaseSchema == null)
                {
                    SetSQLProps();
                }

                return BaseSchema;
            }

        }

    	
        private static void GetTableSchema() 
	    {
            if(!IsSchemaInitialized)
            {
                //Schema declaration
				TableSchema.Table schema = new TableSchema.Table("ItemCategory", TableType.Table, DataService.GetInstance("OpenProject"));
                schema.Columns = new TableSchema.TableColumnCollection();
                schema.SchemaName = @"dbo";
                //columns
                
                TableSchema.TableColumn colvarItemCategoryId = new TableSchema.TableColumn(schema);
                colvarItemCategoryId.ColumnName = "ItemCategoryId";
                colvarItemCategoryId.DataType = DbType.Int32;
                colvarItemCategoryId.MaxLength = 0;
                colvarItemCategoryId.AutoIncrement = false;
                colvarItemCategoryId.IsNullable = false;
                colvarItemCategoryId.IsPrimaryKey = true;
                colvarItemCategoryId.IsForeignKey = false;
                colvarItemCategoryId.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarItemCategoryId);
                
                TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
                colvarTitle.ColumnName = "Title";
                colvarTitle.DataType = DbType.String;
                colvarTitle.MaxLength = 50;
                colvarTitle.AutoIncrement = false;
                colvarTitle.IsNullable = false;
                colvarTitle.IsPrimaryKey = false;
                colvarTitle.IsForeignKey = false;
                colvarTitle.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarTitle);
                
                BaseSchema = schema;
                //add this schema to the provider
                //so we can query it later
                DataService.Providers["OpenProject"].AddSchema("ItemCategory",schema);
            }

        }

        #endregion
        
        #region Query Accessor
	    public static Query CreateQuery()
	    {
		    return new Query(Schema);
	    }

	    #endregion
	    
	    #region .ctors
	    public ItemCategory()
	    {
            SetSQLProps();
            SetDefaults();
            MarkNew();
        }

        
        public ItemCategory(bool useDatabaseDefaults)
	    {
		    SetSQLProps();
		    if(useDatabaseDefaults)
		    {
				ForceDefaults();
			}

			MarkNew();
	    }

	    public ItemCategory(object keyID)
	    {
		    SetSQLProps();
            SetDefaults();
		    LoadByKey(keyID);
	    }

    	 
	    public ItemCategory(string columnName, object columnValue)
        {
            SetSQLProps();
            SetDefaults();
            LoadByParam(columnName,columnValue);
        }

        
	    #endregion
	    
	    #region Props
	    
          
        [XmlAttribute("ItemCategoryId")]
        public int ItemCategoryId 
	    {
		    get { return GetColumnValue<int>("ItemCategoryId"); }

            set 
		    {
			    SetColumnValue("ItemCategoryId", value);
            }

        }

	      
        [XmlAttribute("Title")]
        public string Title 
	    {
		    get { return GetColumnValue<string>("Title"); }

            set 
		    {
			    SetColumnValue("Title", value);
            }

        }

	    
	    #endregion
	    
	    
	    #region PrimaryKey Methods
	    
		public OpenProject.DataObjects.WorkItemCollection WorkItemRecords
		{
			get
			{
				return new OpenProject.DataObjects.WorkItemCollection().Where(WorkItem.Columns.ItemCategoryId, ItemCategoryId).Load();
			}

		}

		#endregion
		
	 	
			
	    
	    //no foreign key tables defined (0)
	    
	    
	    
	    //no ManyToMany tables defined (0)
	    
	    #region ObjectDataSource support
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
	    public static void Insert(int varItemCategoryId,string varTitle)
	    {
		    ItemCategory item = new ItemCategory();
		    
            item.ItemCategoryId = varItemCategoryId;
            
            item.Title = varTitle;
            
	    
		    if (System.Web.HttpContext.Current != null)
			    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
		    else
			    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
	    public static void Update(int varItemCategoryId,string varTitle)
	    {
		    ItemCategory item = new ItemCategory();
		    
                item.ItemCategoryId = varItemCategoryId;
				
                item.Title = varTitle;
				
		    item.IsNew = false;
		    if (System.Web.HttpContext.Current != null)
			    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
		    else
			    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
	    }

	    #endregion
	    #region Columns Struct
	    public struct Columns
	    {
		    
		    
            public static string ItemCategoryId = @"ItemCategoryId";
            
            public static string Title = @"Title";
            
	    }

	    #endregion
    }

}

